package com.utils;

import com.classe.Danos;
import com.classe.Postes;
import com.classe.Rotas;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

    private static final SessionFactory SESSION_FACTORY;
    private static final AnnotationConfiguration cfg;
    static {
        try {
            //adiciona as classes
            cfg = new AnnotationConfiguration();
            cfg.addAnnotatedClass(Danos.class);     
            cfg.addAnnotatedClass(Rotas.class);  
            cfg.addAnnotatedClass(Postes.class); 
            //cfg.addAnnotatedClass(.class);
            
    
            SESSION_FACTORY = cfg.configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static SessionFactory getSessionFactory() {
        return SESSION_FACTORY;
    }

    public static AnnotationConfiguration getCfg() {
        return cfg;
    }
}
